package com.haoze.nurse.utils;

import org.springframework.util.StringUtils;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;

import javax.servlet.http.HttpServletRequest;

public class HttpContextUtil {
    public static HttpServletRequest getHttpServletRequest() {
        return ((ServletRequestAttributes) RequestContextHolder.getRequestAttributes()).getRequest();
    }

    public static String getHeader(String headerName) {
        if (!StringUtils.hasLength(headerName)) {
            return "";
        }
        return getHttpServletRequest().getHeader(headerName);
    }

    public static String getUserId() {
        return getHttpServletRequest().getHeader("zuul_id");
    }

    public static String getLoginName() {
        return getHttpServletRequest().getHeader("zuul_account");
    }
}
